Skip to main content

docker mysql redis

docker run --name some-mysql --restart=always -v /opt/data/mysql/data:/var/lib/mysql -v /opt/data/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=Aq123456 -p 3308:3306  -d mysql:5.7.37

docker run --name some-mysql --restart=always -v /opt/data/mysql/data:/var/lib/mysql -v /opt/data/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=Aq123456 -p 3308:3306 -d mysql:8.0.37

vim docker-compose.yml

version: '2.24' # 可以根据需要选择合适的版本 docker-compose --version
services:
mysql:
image: mysql:5.7.37
container_name: mysql-57
restart: always
volumes:
- ~/data/mysql/data:/var/lib/mysql
- ~/data/mysql/conf.d:/etc/mysql/conf.d
environment:
MYSQL_ROOT_PASSWORD: Aq123456
ports:
- "3308:3306"
command: ["--default-authentication-plugin=mysql_native_password"]

my.cnf

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
#skip-character-set-client-handshake
skip-name-resolve

my.cnf

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/


[mysqld]
skip-host-cache
skip-name-resolve


#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid



[mysqldump]
quick
quote-names
max_allowed_packet = 16M

redis

#创建配置文件
## 1、准备redis配置文件内容
mkdir -p /mydata/redis/conf && vim /mydata/redis/conf/redis.conf


## 2.redis.conf配置示例
appendonly yes
port 6379
bind 0.0.0.0


# 3.docker启动redis
docker run -d -p 6379:6379 --restart=always \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /mydata/redis-01/data:/data \
--name redis-01 redis:6.2.5 \
redis-server /etc/redis/redis.conf